package com.feng.gateway.fallback;

import com.alibaba.fastjson.JSONObject;
import com.feng.common.model.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * 熔断处理
 *
 * @author: jack.Cheng
 * @date: 2022/6/2 15:07
 */
@RestController
@RequestMapping("gateway")
public class FallbackController {

    /**
     * 回调处理
     */
    @GetMapping("fallback")
    public Mono<String> fallback() {
        return Mono.just(JSONObject.toJSONString(Result.fail("默认回调,服务不可用")));
    }

    /**
     * 熔断回调处理
     */
    @GetMapping("fallback/circuitbreaker")
    public Mono<String> circuitbreaker() {
        return Mono.just(JSONObject.toJSONString(Result.fail("触发熔断")));
    }

    /**
     * 限流回调处理
     */
    @GetMapping("fallback/ratelimiter")
    public Mono<String> ratelimiter() {
        return Mono.just(JSONObject.toJSONString(Result.fail("触发限流")));
    }
}
